package com.qf.error;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 使用配置方式实现的全局异常处理器
 * @author 千锋健哥
 */
public class MyHandlerExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        //打印异常堆栈信息
        e.printStackTrace();

        ModelAndView modelAndView = new ModelAndView();
        //传给页面中显示的数据
        modelAndView.addObject("error", "不好意思, 网络繁忙, 请原谅!!!");
        //指定跳转的页面的位置和名称
        modelAndView.setViewName("error");
        return modelAndView;
    }

}
